package com.jjc.android.activity

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.jjc.android.Constants
import com.jjc.android.R
import com.jjc.android.base.BaseActivity
import com.jjc.android.dialog.MessageImageDialog
import com.jjc.android.util.messenger.ActivityMessenger
import com.jjc.android.view.onClick

class InsertCardActivity : BaseActivity() {

    companion object{
        fun start(context: Activity, action:(Boolean)->Unit){
            val intent = Intent(context,InsertCardActivity::class.java)
            ActivityMessenger.startActivityForResult(context,intent){
                (it?.getBooleanExtra(Constants.BUNDLE_INFO,false)==true).let(action)
            }
        }
    }

    override val layoutId: Int = R.layout.activity_insert_card
    private val okBtn: TextView by lazy { findViewById<TextView>(R.id.okBtn) }
    private val homeBtn:View by lazy { findViewById(R.id.homeBtn) }
    private val insertImageView:ImageView by lazy { findViewById(R.id.insertImageView) }

    override fun initView(savedInstanceState: Bundle?) {
        setActivityTitle(getString(R.string.insert_device_txt))
        okBtn.onClick {
            setResult(Activity.RESULT_OK, Intent().apply {
                putExtra(Constants.BUNDLE_INFO,true)
            })
            finish()
        }
        homeBtn.visibility = View.VISIBLE
        homeBtn.onClick {
            MessageImageDialog.Builder(this)
                .imageResId(R.mipmap.alert_jiancejindu_pic)
                .content(getString(R.string.dete_not_save_txt))
                .okClick {
                    MainActivity.start(this)
                }
                .build()
                .show()
        }

        Glide
            .with(this)
            .asGif()
            .load(R.mipmap.insert_card_gif_icon_2)
            .into(insertImageView)
    }

}